{# Modal for request action #}
<div class='modal fade' id='requestActionModal' tabindex='-1' role='dialog' aria-labelledby='requestActionModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='requestActionModalLabel'>{{ 'Request action'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body'>
        {# SELECT ACTION #}
        <label for='requestActionActionSelect'>{{ 'Select action'|trans }}</label>
        <select id='requestActionActionSelect' class='form-control'>
          {% for value, text in requestableActionArr|default([])|sort %}
            <option value='{{ value }}'>{{ text }}</option>
          {% endfor %}
        </select>
        {# SELECT USER #}
        <label for='requestActionUserSelect'>{{ 'Select collaborator'|trans }}</label>
        {# this exists so Firefox doesn't process the Search user field as password. No idea why it would do it in the first place though... #}
        {# and autocomplete='off' doesn't work #}
        <input type='password' disabled hidden />
        <input type='text' placeholder='{{ 'Search user'|trans }}' id='requestActionUserSelect' class='form-control' data-identifier='requestActionUserSelect' data-action='autocomplete' data-target='users'>
        <div id='autocompleteAnchorDiv_requestActionUserSelect'></div>
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-secondary' data-dismiss='modal'>{{ 'Close'|trans }}</button>
        <button type='button' class='btn btn-primary' data-dismiss='modal' data-action='requestaction'>{{ 'Save'|trans }}</button>
      </div>
    </div>
  </div>
</div>
{% include 'duplicate-modal.html' %}
{# Modal for timestamping #}
<div class='modal fade' id='timestampModal' tabindex='-1' role='dialog' aria-labelledby='timestampModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='timestampModalLabel'>{{ 'Timestamp Entry'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body' data-wait='{{ 'Please wait…'|trans }}'>
        <p>{{ 'Timestamping an entry will create an irrefutable proof that the data was present at this point in time. You can timestamp an entry as many times as necessary: an immutable timestamp archive will be created each time, and stored as attachment.'|trans }}</p>
        <p>{{ 'With Trusted Timestamping (RFC3161), a cryptographic hash of your data is sent to a trusted third party. They reply with a token containing the current time, and they sign the token with their private key.'|trans }}</p>
      </div>
      <div class='timestamp-error'></div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-ghost' data-dismiss='modal'>{{ 'Cancel'|trans }}</button>
        <button type='button' data-action='timestamp' data-dismiss='modal' class='btn btn-primary'>{{ 'Timestamp'|trans }}</button>
      </div>
    </div>
  </div>
</div>

{# Modal for blockchain timestamping #}
<div class='modal fade' id='blocktimestampModal' tabindex='-1' role='dialog' aria-labelledby='blocktimestampModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='blocktimestampModalLabel'>{{ 'Timestamp Entry'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body' data-wait='{{ 'Please wait…'|trans }}'>
        {# this first paragraph is the same as above for trusted timestamping #}
        <p>{{ 'Timestamping an entry will create an irrefutable proof that the data was present at this point in time. You can timestamp an entry as many times as necessary: an immutable timestamp archive will be created each time, and stored as attachment.'|trans }}</p>
        <p>{{ 'With Blockchain Timestamping, the cryptographic fingerprint of your data is added to a blockchain that is impossible to modify. This function uses the Bloxberg Consortium blockchain based on Ethereum.'|trans }}</p>
      </div>
      <div class='timestamp-error'></div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-ghost' data-dismiss='modal'>{{ 'Cancel'|trans }}</button>
        <button type='button' data-action='bloxberg' data-dismiss='modal' class='btn btn-primary'>{{ 'Timestamp'|trans }}</button>
      </div>
    </div>
  </div>
</div>

{# Modal for signature #}
<div class='modal fade' id='addSignatureModal' tabindex='-1' role='dialog' aria-labelledby='addSignatureModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='addSignatureModalLabel'>{{ 'Add signature'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      {% if App.Users.userData.sig_privkey %}
        <form id='sigPassphraseForm' aria-label='{{ 'Add your signature'|trans }}'>
      {% endif %}
        <div class='modal-body' data-wait='{{ 'Please wait…'|trans }}'>
          <p>{{ 'Adding your signature will cryptographically sign the content of this entry, and the signature will be stored alongside the content at the time of signature, in an archive, visible as attachment (masked by default because archived).'|trans }}</p>
          {% if not App.Users.userData.sig_privkey %}
            <p>{{ 'Your account is missing a cryptographic key pair, necessary for signature. You must generate one from your User Control Panel before you can sign an entry.'|trans }}</p>
          {% else %}
              <label for='sigMeaningSelect'>{{ 'Select a meaning for this signature'|trans }}</label>
              <select id='sigMeaningSelect' class='form-control' name='meaning'>
                {% for meaning, text in meaningArr|default([])|sort %}
                  <option value='{{ meaning }}'>{{ text }}</option>
                {% endfor %}
              </select>

              <label for='sigPassphraseInput'>{{ 'Enter your passphrase to unlock your secret key:'|trans }}</label>
              <div class='input-group'>
                <input class='form-control' type='password' required name='passphrase' minlength='{{ App.Config.configArr.min_password_length }}' autocomplete='off' id='sigPassphraseInput' />
                <div class='input-group-append'>
                  <button type='button' class='btn btn-light input-border' data-action='toggle-password' title='{{ 'Show password'|trans }}' aria-label='{{ 'Show password'|trans }}'><i class='fas fa-eye' aria-hidden='true'></i></button>
                </div>
              </div>
          {% endif %}
        </div>
        <div class='modal-footer'>
          <button type='button' class='btn btn-ghost' data-dismiss='modal'>{{ 'Cancel'|trans }}</button>
          {% if App.Users.userData.sig_privkey %}
            <button type='submit' data-action='sign' {{ not App.Users.userData.sig_privkey ? 'disabled' }} class='btn btn-primary'>{{ 'Add your signature'|trans }}</button>
          {% else %}
            <a class='btn btn-primary' href='/ucp.php?tab=2#ucp-sigkeys'>{{ 'Go to Settings'|trans }}</a>
          {% endif %}
        </div>
      {% if App.Users.userData.sig_privkey %}
        </form>
      {% endif %}
    </div>
  </div>
</div>
{# only show for items, if shown to experiments, it'll trigger an error with toSymbol not having an int value #}
{% if Entity.entityType.value == 'items' %}
{# Modal for procurement request #}
<div class='modal fade' id='procurementRequestModal' tabindex='-1' role='dialog' aria-labelledby='procurementRequestModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='procurementRequestModalLabel'>{{ 'Create procurement request'|trans }}</h5>
        <button type='button' class='close' data-dismiss='modal' aria-label='{{ 'Close'|trans }}'>
          <span aria-hidden='true'>&times;</span>
        </button>
      </div>
      <div class='modal-body'>
        <p>{{ 'This resource can be purchased. It costs %.2f %s for %d units.'|format(Entity.entityData.proc_price_tax, Entity.entityData.proc_currency|toSymbol, Entity.entityData.proc_pack_qty)|trans }}</p>
        <label for='procurementRequestQtyInput'>{{ 'Enter a quantity to purchase'|trans }}</label>
        <input class='form-control' type='number' min='0' value='1' id='procurementRequestQtyInput' />
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-ghost' data-dismiss='modal'>{{ 'Cancel'|trans }}</button>
        <button type='button' data-action='createprocurementrequest' data-dismiss='modal' class='btn btn-primary'>{{ 'Place order'|trans }}</button>
      </div>
    </div>
  </div>
</div>
{% endif %}

<hr>

{# TOP TOOLBAR #}
<div class='d-flex align-items-center flex-wrap' id='topToolbar'>
  {% include 'back-to-previous.html' %}
  {# for templates: create from button #}
  {% if Entity.entityType.value == 'experiments_templates' or Entity.entityType.value == 'items_types' %}
  <a data-action='create-entity' data-type='{{ Entity.entityType.value == 'experiments_templates' ? 'experiments' : 'items' }}' data-tplid='{{ Entity.id }}' href='#' class='btn hl-hover-gray p-2 lh-normal border-0' title='{{ 'Create entry from template'|trans }}' aria-label='{{ 'Create entry from template'|trans }}'>
      <i class='color-blue fas fa-file-circle-plus fa-fw'></i>
    </a>
  {% endif %}

  <div class='vertical-separator'></div>

  {% if mode == 'edit' %}
    {# VIEW button #}
    <a title='{{ 'View mode'|trans }}' aria-label='{{ 'View mode'|trans }}' href='?mode=view&amp;id={{ Entity.id }}' class='btn hl-hover-gray p-2 mr-2 main-action-button lh-normal border-0'>
      <i class='fas fa-eye fa-fw'></i>
    </a>
  {% else %}
    {# EDIT button #}
    <a title='{{ 'Edit'|trans }}' aria-label='{{ 'Edit'|trans }}' href='?mode=edit&amp;id={{ Entity.id }}' class='btn hl-hover-gray p-2 mr-2 rounded main-action-button lh-normal border-0 {{ Entity.isReadOnly ? 'disabled' }}'>
      <i class='fas fa-pencil fa-fw'></i>
    </a>
  {% endif %}

  {% if not App.Session.has('is_anon') %}

    {# DUPLICATE #}
    <button type='button' title='{{ 'Duplicate'|trans }}' aria-label='{{ 'Duplicate'|trans }}' data-action='toggle-modal' data-target='duplicateModal' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0'>
      <i class='fas fa-clone fa-fw'></i>
    </button>

    {# Calendar booking #}
    {% if Entity.entityType.value == 'items' and (Entity.entityData.is_bookable or not Entity.isReadOnly) %}
      {% if Entity.entityData.is_bookable %}
        <a class='btn mr-2 hl-hover-gray p-2 lh-normal border-0' title='{{ 'Book item'|trans }}' aria-label='{{ 'Book item'|trans }}' href='scheduler.php?items[]={{ Entity.id }}'>
          <i class='fas fa-calendar-plus fa-fw'></i>
        </a>
        <button type='button' class='btn border-0 lh-normal hl-hover-gray p-2 mr-2' aria-label='{{ 'Send an email to users who have booked this resource within the 4 last & upcoming months.'|trans }}' title='{{ 'Send an email to users who have booked this resource within the 4 last & upcoming months.'|trans }}' data-action='toggle-modal' data-target='sendBookingsEmailModal'>
          <i class='fas fa-fw fa-envelope'></i>
        </button>
      {% else %}
        <button type='button' class='btn mr-2 hl-hover-gray p-2 lh-normal border-0' aria-label='{{ 'Modify booking parameters'|trans }}' title='{{ 'Modify booking parameters'|trans }}' data-action='toggle-modal' data-target='bookingParamsModal'>
          <i class='fas fa-calendar-plus color-disabled fa-fw'></i>
        </button>
      {% endif %}
    {% endif %}

  {% endif %}

  {# SIGN #}
  <button type='button' id='actionButton-sign' title='{{ 'Add signature'|trans }}' aria-label='{{ 'Add signature'|trans }}' data-action='toggle-modal' data-target='addSignatureModal' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0'>
    <i class='fas fa-signature fa-fw'></i>
  </button>

  {# TIMESTAMP #}
  {% if not App.Session.has('is_anon') %}
    <button type='button' title='{{ 'Timestamp'|trans }}' aria-label='{{ 'Timestamp'|trans }}' data-action='do-requestable-action' data-target='timestamp' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0'>
      <i class='fas fa-calendar-check fa-fw'></i>
    </button>
  {% endif %}

  {# BLOXBERG TIMESTAMP #}
  {% if App.Config.configArr.blox_enabled %}
    <button type='button' title='{{ 'Add to blockchain'|trans }}' aria-label='{{ 'Add to blockchain'|trans }}' data-action='toggle-modal' data-target='blocktimestampModal' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0'>
      <i class='fas fa-cubes fa-fw'></i>
    </button>
  {% endif %}

  {# PROCUREMENT REQUEST #}
  {% if Entity.entityType.value == 'items' and (Entity.entityData.is_procurable or not Entity.isReadOnly) %}
  {% set proc_label = Entity.entityData.is_procurable ? 'Place order'|trans : 'Modify procurement parameters'|trans %}
    <button type='button' title='{{ proc_label }}' aria-label='{{ proc_label }}' data-action='toggle-modal' data-target='procurement{{ Entity.entityData.is_procurable ? 'Request' : 'Params' }}Modal' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0 {{ not Entity.entityData.is_procurable ? 'disabled' }}'>
      <i class='fas fa-cart-shopping fa-fw'></i>
    </button>
  {% endif %}

  {% if not App.Session.has('is_anon') %}
    <div class='vertical-separator'></div>
  {% endif %}

  {# DOWNLOAD / EXPORT MENU #}
  {% include 'export-menu.html' %}

  <div class='ml-auto d-flex flex-wrap align-items-center'>
    {% if not App.Session.has('is_anon') %}
    {% if mode == 'edit' %}
      {# RATING EDIT #}
      <div class='rating mr-2 align-items-center' id='editRatingDiv'>
        <span class='cancel-button' data-trigger='click' data-model='{{ Entity.entityType.value }}/{{ Entity.entityData.id }}' data-target='rating' data-value='0' data-reload='editRatingDiv'><i class='fas fa-ban fa-fw'></i></span>
        {% for i in range(5, 1) %}
          <input {{ Entity.entityData.rating == i ? 'checked="checked"' }} type='radio' id='star{{ i }}' data-trigger='change' data-model='{{ Entity.entityType.value }}/{{ Entity.entityData.id }}' data-target='rating' data-value='{{ i }}' data-reload='editRatingDiv' value='{{ i }}' /><label for='star{{ i }}' aria-label='{{ i }} star {{- i > 1 ? 's' }}'></label>
        {% endfor %}
      </div>
    {% else %}
      {# RATING VIEW #}
      {% if Entity.entityData.rating > 0 %}
        <span class='rating-show rounded p-1 mr-3'><i class='fas fa-star' title='☻'></i>{{ Entity.entityData.rating }}</span>
      {% endif %}
    {% endif %}

      {# TOGGLE PIN #}
      {% include 'toggle-pin.html' %}

      {# LOCK #}
      {% set lockIcon = 'fa-lock-open' %}
      {% set alt = 'Lock/Unlock item'|trans %}
      {% if Entity.entityData.locked %}
          {% set lockIcon = 'fa-lock' %}
          {% set alt = Entity.entityData.locked_at %}
      {% endif %}
      <button type='button' title='{{ alt }}' aria-label='{{ alt }}' data-action='do-requestable-action' data-target='lock' class='btn {{ Entity.entityData.locked ? 'bgnd-gray' : 'hl-hover-gray' }} p-2 mr-2 lh-normal border-0'>
        <i class='fas {{ lockIcon }} fa-fw'></i>
      </button>
    {% endif %}

    {# REQUEST ACTION #}
    <button type='button' class='btn hl-hover-gray p-2 mr-2 lh-normal border-0' title='{{ 'Request action'|trans }}' aria-label='{{ 'Request action'|trans }}' data-action='toggle-modal' data-target='requestActionModal'>
      <i class='fas fa-person-circle-exclamation fa-fw' title='{{ 'Request action'|trans }}'></i>
    </button>

    <div class='vertical-separator'></div>
    {# MORE OPTIONS #}
    <div class='dropdown'>
      <button data-toggle='dropdown' aria-haspopup='true' aria-expanded='false' title='{{ 'More options'|trans }}' aria-label='{{ 'More options'|trans }}' type='button' class='btn hl-hover-gray p-2 lh-normal border-0'>
        <i class='fas fa-fw fa-ellipsis-v'></i>
      </button>

      <div class='dropdown-menu dropdown-menu-right'>
        {% if Entity.entityType.value == 'items' %}
          {# BOOKING PARAMS #}
          <button type='button' class='dropdown-item' data-action='toggle-modal' data-target='bookingParamsModal'><i class='fas fa-calendar-plus fa-fw' title='{{ 'Modify booking parameters'|trans }}'></i> {{ 'Modify booking parameters'|trans }}</button>
          {# PROCUREMENT #}
          <button type='button' class='dropdown-item' data-action='toggle-modal' data-target='procurementParamsModal'><i class='fas fa-cart-shopping fa-fw' title='{{ 'Modify procurement parameters'|trans }}'></i> {{ 'Modify procurement parameters'|trans }}</button>
        {% endif %}
        {# TRANSFER OWNERSHIP #}
        {% if Entity.entityData.userid == App.Users.userData.userid or App.Users.isAdmin %}
          <button type='button' class='dropdown-item' data-action='toggle-modal' data-target='ownerModal'><i class='fas fa-people-arrows fa-fw' title='{{ 'Transfer ownership'|trans }}'></i> {{ 'Transfer ownership'|trans }}</button>
        {% endif %}
        {# REVISIONS #}
        <a class='dropdown-item' href='revisions.php?type={{ Entity.entityType.value }}&amp;item_id={{ Entity.id }}'><i class='fas fa-history fa-fw'></i> {{ 'See revisions'|trans }}</a>
        {# CHANGELOG #}
        <a class='dropdown-item' href='?id={{ Entity.id }}&amp;mode=changelog'><i class='fas fa-list fa-fw' title='{{ 'See changelog'|trans }}'></i> {{ 'See changelog'|trans }}</a>

        {% if not App.Session.has('is_anon') %}
          {# ARCHIVE / UNARCHIVE #}
          {% if Entity.entityData.state == enum('Elabftw\\Enums\\State').Normal.value %}
            <button type='button' class='dropdown-item hover-warning' data-action='do-requestable-action' data-target='archive'>
              <i class='fas fa-fw fa-box-archive' title='{{ 'Archive'|trans }}'></i> {{ 'Archive'|trans }}
            </button>
          {% elseif Entity.entityData.state == enum('Elabftw\\Enums\\State').Archived.value %}
            <button type='button' class='dropdown-item hover-warning' data-action='do-requestable-action' data-target='unarchive'>
              <i class='fas fa-fw fa-box-archive' title='{{ 'Unarchive'|trans }}'></i> {{ 'Unarchive'|trans }}
            </button>
          {% endif %}
        {% endif %}
        <div class='dropdown-divider'></div>
        {# DELETE / RESTORE #}
        {% if Entity.entityData.state == enum('Elabftw\\Enums\\State').Normal.value %}
          <button type='button' class='dropdown-item hover-danger' data-action='destroy'><i class='fas fa-trash-alt fa-fw' title='{{ 'Delete'|trans }}'></i> {{ 'Delete'|trans }}</button>
        {% elseif Entity.entityData.state == enum('Elabftw\\Enums\\State').Deleted.value %}
          <button type='button' class='dropdown-item hover-danger' data-action='restore'><i class='fas fa-trash-can-arrow-up fa-fw' title='{{ 'Restore entry'|trans }}'></i> {{ 'Restore entry'|trans }}</button>
        {% endif %}
      </div>
    </div>
  </div>
</div>

<hr>
